import Collectable
import pygame

class Missile(Collectable.Collectable):
	def drawingInformation(self):
		if self.cur_room and not (self in self.cur_room.collectablesList):
			return self.getImageThrown()
		return Collectable.Collectable.drawingInformation(self)
	def __init__(self,x=0,y=0,mass=16.3804815,image=None):
		Collectable.Collectable.__init__(self,x=x,y=y,mass=mass)
		self.image=image
		self.angle=0
	def getHeight(self):
		return self.image.get_height()
	def getWidth(self):
		return self.image.get_width()
	def getFullHeight(self):
		self.getHeight()
	def isAlive(self):
		return False
	def attack(self,user):
		l=user.look
		ll=(l[0]**2+l[1]**2)**0.5
		self.x=user.x
		self.y=user.y+user.getHeight()-40
		speed=3*580*1.0/24
		self.prev_x=self.x-speed*l[0]/ll
		self.prev_y=self.y-speed*l[1]/ll
		self.cur_room=user.cur_room
		self.fraction=user.fraction
		user.cur_room.projectilesList.append(self)
		user.weaponEquipped=None
	def takenBy(self,him):
		if him.weaponEquipped is None:
			him.weaponEquipped=self
		else:
			Collectable.Collectable.takenBy(self,him)
	def postcondition(self):
		pass
	def getImageThrown(self):
		a=-45 if (self.x-self.prev_x)*(self.y-self.prev_y)>=0 else 45
		self.angle=(self.angle+a)%360
		im=pygame.transform.rotate(self.image,self.angle)
		return (self.x-0.5*self.getWidth(),self.y+self.getHeight()),im